
Ext.namespace("Ext.milan.pagejs.page_officeItems");
Ext.milan.pagejs.page_officeItems.userWin = null;
Ext.milan.pagejs.page_officeItems.subWin = null;
Ext.milan.pagejs.page_officeItems.REQUEST_ACTION = "officeItems";
var selectPostionTree = null;
Ext.milan.pagejs.page_officeItems.docLoadBeforeCallBack = function() {
};

Ext.milan.pagejs.page_officeItems.docOnReadyCallback = function() {

};

/**
 * 关闭子弹出窗口
 */
Ext.milan.pagejs.page_officeItems.closeSubWin = function() {
	Milan.commonutils.closeModelPop(Ext.milan.pagejs.page_officeItems.subWin);
};

/**
 * 关闭弹出窗口
 */
Ext.milan.pagejs.page_officeItems.closeWin = function(winName) {
	if(winName){
		if(winName=='inactivateConsignerWin')
			inactivateConsignerWin.closeDialog();
	}
	else
		Milan.commonutils.closeModelPop(Ext.milan.pagejs.page_officeItems.userWin);
};

/*------------------------ private methods -----------------------*/

/**
 * 查询所有
 */
Ext.milan.pagejs.page_officeItems._search = function() {
	Ext.milan.pagejs.common_utils.query(false, "officeItems/list.do");
};

Ext.milan.pagejs.page_officeItems._formCheck = function(frm) {
	function focusElement(el) {
		if(el.focus)
			el.focus();
	};
	if(frm.lb.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "类别 不能为空！");
		return false;
	}
	if(frm.mc.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "名称 不能为空！");
		return false;
	}
	if(frm.sl.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "数量 不能为空！");
		return false;
	}
	if(frm.dw.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "单位 不能为空！");
		return false;
	}
	return true;
};

/**
 * 保存信息
 */
Ext.milan.pagejs.page_officeItems._saveInfo = function(formId) {
	if(!Ext.milan.pagejs.page_officeItems._formCheck($(formId)))
		return;
		
	Milan.ajaxutility.formSubmit({
		form:formId,
		success:function(response)
		{
			Ext.milan.pagejs.page_officeItems.closeWin();
			Ext.milan.pagejs.page_officeItems.query();
		}
	});
};

/**
 * 条件查询列表
 */
Ext.milan.pagejs.page_officeItems.query = function() {
	Milan.pagejs.page_index.updateCurrentTabByForm("query_officeItems_list_form");
};

/**
 * 显示新建表单
 */
Ext.milan.pagejs.page_officeItems.showAddForm = function() {
	var url = Ext.milan.pagejs.page_officeItems.REQUEST_ACTION + "/create.do";
	Ext.milan.pagejs.page_officeItems.userWin = Milan.commonutils.createModelPop({
		title:"新建", 
		url:url,
		width:650
	});
};

/**
 * 显示编辑表单
 * 
 * @param ID
 */
Ext.milan.pagejs.page_officeItems.showEditForm = function(id) {
	var url = Ext.milan.pagejs.page_officeItems.REQUEST_ACTION + "/edit.do?id=" + id;
	Ext.milan.pagejs.page_officeItems.userWin = Milan.commonutils.createModelPop({
		title:"编辑",
		url:url,
		width:650
	});
};

/**
 * 保存新建用户信息
 */
Ext.milan.pagejs.page_officeItems.save = function(formId) {
	Ext.milan.pagejs.page_officeItems._saveInfo(formId);
};

/**
 * 保存编辑后的信息
 */
Ext.milan.pagejs.page_officeItems.edit = function(formId) {
	Ext.milan.pagejs.page_officeItems._saveInfo(formId);
};

Ext.milan.pagejs.page_officeItems.deleteForm = function(id) {
	var url = Ext.milan.pagejs.page_officeItems.REQUEST_ACTION + "/delete.do?id=" + id;
	new Milan.widget.ConfirmDialog("确认信息", "确认要删除该信息吗？", {
		confirmCallback: function() {
			Milan.ajaxutility.formSubmit({
				url: url,
				method: 'post',
				success: function(response, option)
				{
					Ext.milan.pagejs.page_officeItems.query();
				}
			});
		}
	});	
};

/**
 * 查看详情
 * 
 * @param entityId 用户ID
 */
Ext.milan.pagejs.page_officeItems.viewDetail = function(entityId) {
	var url = Ext.milan.pagejs.page_officeItems.REQUEST_ACTION + "/show.do?id=" + entityId;
	Ext.milan.pagejs.page_officeItems.userWin = Milan.commonutils.createModelPop({
		title:"详细信息",
		url:url,
		width:500
	});
};

Ext.milan.pagejs.page_officeItems.query2 = function(formId) {
	var formEle = $(formId);
	Milan.ajaxutility.formSubmit({
		form : formId,
		success: function(response,option)
		{
			if(formEle.pagingCnt&&formEle.pagingCnt.value)
			{
				Milan.ajaxutility.updateContainer(formEle.pagingCnt.value,response.responseText);
				
				return;
			}
			Milan.pagejs.page_index.updateCurrentTab(response.responseText);
		}
	});
};

Ext.milan.pagejs.page_officeItems.selectWp = function(formId)
{
    var url = "officeItems/select.do";
	Ext.milan.pagejs.page_officeItems.userWin = Milan.commonutils.createModelPop({
		title:"办公用品库", 
		url:url,
		width:650
	});
}

Ext.milan.pagejs.page_officeItems.addWp = function(formId) {
	var formEle = $(formId);
	if((Ext.milan.pagejs.page_officeItems.selectCount(formEle)== 0)){
		Milan.commonutils.createDelayNotifyModel('提示信息',"请选择要添加物品！");
		return false;
	}
	else{
		var typeId ;
		var typeMc ;
		var types = formEle.selectCheck;
		if(types){
			if (types.length){
				for (i = 0; i < types.length; i++){
					if (types[i].checked){
						typeId = types[i].value;
						typeMc = types[i].mc;
					}
				}
			}
			else{
				if(types.checked){
					typeId = types.value;
					typeMc = types.mc;
				}
			}
		}
		document.getElementById('_wp_of_add_wf').innerHTML = typeMc;
		$('wpid').value=typeId;
		Milan.commonutils.closeModelPop(Ext.milan.pagejs.page_officeItems.userWin);
	}
};

Ext.milan.pagejs.page_officeItems.selectCount = function(formEle)
{
	var types = formEle.selectCheck;
	var selCount=0;
	if (types!=null)
	{
		if (types.length!= null) 
		{
			for (i = 0; i < types.length; i++) 
			{
				if (types[i].checked) 
				{
					selCount++;
				}
			}
		}
		else 
		{
			if (types.checked) 
				selCount++;
		}
	}
	return selCount;
}